set(SOURCES "main.cc" 
            "settings.cc"
            "system_info.cc"
            "application.cc"
            "button_handler.cc"
            "ota.cc"
            "background_task.cc"
            "audio_codecs/audio_codec.cc"
            "audio_codecs/no_audio_codec.cc"
            "audio_codecs/box_audio_codec.cc"
            "audio_codecs/es8311_audio_codec.cc"
            "audio_codecs/es8374_audio_codec.cc"
            "audio_codecs/es8388_audio_codec.cc"
            "audio_processing/afe_audio_processor.cc"
            "audio_processing/wake_word_detect.cc"
            "protocols/mqtt_protocol.cc"
            "protocols/protocol.cc"
            "protocols/websocket_protocol.cc"
            "iot/thing.cc"
            "iot/thing_manager.cc"
            "led/single_led.cc"
            "led/circular_strip.cc"
            "led/gpio_led.cc"
            "display/display.cc"
            "display/lcd_display.cc"
)

set(INCLUDE_DIRS "."  "audio_codecs" "audio_processing" "display" "assets" "iot" "protocols" "led")

# 添加 IOT 相关文件
file(GLOB IOT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/iot/things/*.cc)
list(APPEND SOURCES ${IOT_SOURCES})

# 添加板级公共文件
file(GLOB BOARD_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/boards/common/*.cc)
list(APPEND SOURCES ${BOARD_COMMON_SOURCES})
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/boards/common)

# 根据 BOARD_TYPE 配置添加对应的板级文件
if(CONFIG_BOARD_TYPE_ESP_BOX_3)
    set(BOARD_TYPE "esp-box-3")
elseif(CONFIG_BOARD_TYPE_HONOKA_V1)
    set(BOARD_TYPE "honoka-board-1")
endif()
file(GLOB BOARD_SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.c
)
list(APPEND SOURCES ${BOARD_SOURCES})
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE})

# 根据 BOARD_TYPE 配置添加UI文件
if(CONFIG_BOARD_TYPE_ESP_BOX_3)
    set(UI_FILES "ui_320x240")
elseif(CONFIG_BOARD_TYPE_HONOKA_V1)
    set(UI_FILES "ui_320x240")
endif()
file(GLOB UI_SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/display/${UI_FILES}/screen/*.c
    ${CMAKE_CURRENT_SOURCE_DIR}/display/${UI_FILES}/generate/*.c
    ${CMAKE_CURRENT_SOURCE_DIR}/display/${UI_FILES}/generate/components/*.c
    ${CMAKE_CURRENT_SOURCE_DIR}/display/${UI_FILES}/generate/fonts/*.c
    ${CMAKE_CURRENT_SOURCE_DIR}/display/${UI_FILES}/generate/images/*.c
    ${CMAKE_CURRENT_SOURCE_DIR}/display/${UI_FILES}/generate/screens/*.c
)
list(APPEND SOURCES ${UI_SOURCES})
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/display/${UI_FILES}/screen)
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/display/${UI_FILES}/generate)

# 根据Kconfig选择语言目录
if(CONFIG_LANGUAGE_ZH_CN)
    set(LANG_DIR "zh-CN")
elseif(CONFIG_LANGUAGE_ZH_TW)
    set(LANG_DIR "zh-TW")
elseif(CONFIG_LANGUAGE_EN_US)
    set(LANG_DIR "en-US")
elseif(CONFIG_LANGUAGE_JA_JP)
    set(LANG_DIR "ja-JP")
endif()

# 定义生成路径
set(LANG_JSON "${CMAKE_CURRENT_SOURCE_DIR}/assets/${LANG_DIR}/language.json")
set(LANG_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/assets/lang_config.h")
file(GLOB LANG_SOUNDS ${CMAKE_CURRENT_SOURCE_DIR}/assets/${LANG_DIR}/*.p3)
file(GLOB COMMON_SOUNDS ${CMAKE_CURRENT_SOURCE_DIR}/assets/common/*.p3)


idf_component_register(SRCS ${SOURCES}
                    EMBED_FILES ${LANG_SOUNDS} ${COMMON_SOUNDS}
                    INCLUDE_DIRS ${INCLUDE_DIRS}
                    WHOLE_ARCHIVE
                    )

if(NOT BOARD_NAME)
    set(BOARD_NAME ${BOARD_TYPE})
endif()
target_compile_definitions(${COMPONENT_LIB}
    PRIVATE BOARD_TYPE=\"${BOARD_TYPE}\" BOARD_NAME=\"${BOARD_NAME}\"
    )